using Godot;

public partial class Icon : Sprite2D
{
	[Export] float moveSpeed = 100;
	private Timer lifeTimer;
	private Vector2 direction;
	public bool usePool = false;
	public bool isInTree = false;
	public NodePool iconPool;
	public override void _Ready()
	{
		isInTree = true;
		lifeTimer = GetNode<Timer>("Timer");
		lifeTimer.Timeout += Destory;
		if (!usePool) Init();
	}

	public override void _PhysicsProcess(double delta)
	{
		Position += direction * moveSpeed * (float)delta;
	}

	public void Init()
	{
		lifeTimer.Start();
		direction = new Vector2(Mathf.Cos(Rotation), Mathf.Sin(Rotation));
	}

	public void Destory()
	{
		if (usePool)
		{
			iconPool.PutNode(this);
		}
		else
		{
			QueueFree();
		}
	}
}
